import sys
import os
from pprint import pprint


def curr(path):
    """取得脚本所在目录的相对位置"""
    exec = sys.argv[0]
    return os.path.join(os.path.dirname(exec), path)


def gen_sub_line(line):
    LINE_LENGTH = 80
    while True:
        curr = line[:LINE_LENGTH]
        line = line[LINE_LENGTH:]
        yield curr
        if not line:
            break


def gen_lines():
    """每行不超过80个字"""
    with open(curr("4447.txt"), "rt", encoding="utf-8") as fin:
        for line in fin:
            yield from gen_sub_line(line.rstrip())


def gen_pages():
    """每次不超过10个行"""
    with open(curr("4447.txt"), "rt", encoding="utf-8") as fin:
        fin.readline(10)


lines = enumerate(gen_lines(), 0)
first_page = [line for i, line in lines if i < 100]
pprint(first_page)
